package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.PropertyScrap;
import com.ruoyi.system.domain.vo.PropertyScrapVo;
import com.ruoyi.system.service.IPropertyScrapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;

/**
 * 资产报废记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system/scrap")
public class PropertyScrapController extends BaseController
{
    @Autowired
    private IPropertyScrapService propertyScrapService;

    /**
     * 查询资产报废记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PropertyScrapVo propertyScrap)
    {
        startPage();
        List<PropertyScrapVo> list = propertyScrapService.selectPropertyScrapList(propertyScrap);
        return getDataTable(list);
    }

    /**
     * 导出资产报废记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:export')")
    @Log(title = "资产报废记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyScrapVo propertyScrap)
    {
        List<PropertyScrapVo> list = propertyScrapService.selectPropertyScrapList(propertyScrap);
        ExcelUtil<PropertyScrapVo> util = new ExcelUtil<PropertyScrapVo>(PropertyScrapVo.class);
        util.exportExcel(response, list, "资产报废记录数据");
    }

    /**
     * 获取资产报废记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(propertyScrapService.selectPropertyScrapById(Long.valueOf(id)));
    }

    /**
     * 新增资产报废记录
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:add')")
    @Log(title = "资产报废记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyScrap propertyScrap)
    {
        return toAjax(propertyScrapService.insertPropertyScrap(propertyScrap));
    }

    /**
     * 修改资产报废记录
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:edit')")
    @Log(title = "资产报废记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyScrap propertyScrap)
    {
        return toAjax(propertyScrapService.updatePropertyScrap(propertyScrap));
    }

    /**
     * 删除资产报废记录
     */
    @PreAuthorize("@ss.hasPermi('system:scrap:remove')")
    @Log(title = "资产报废记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(propertyScrapService.deletePropertyScrapByIds(ids));
    }
}
